package kuonjisai;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class J03_MemberDAO  implements J03_IMemberDAO{

	
	private String DRV = "oracle.jdbc.driver.OracleDriver";
	private String URL = "jdbc:oracle:thin:cjhmasterola/cjhmasterola@112.216.253.125:1521:xe";
	private String insertSQL = "insert into J03MEMBER values( exam.nextval, ?, ?, ?, ?, sysdate )";
	private String selectSQL = "select * from J03MEMBER order by mno desc";
	
	
	
	
	@Override
	public boolean insertMember(J03_MemberVO m) {
		Connection conn = null;
		PreparedStatement pstmt = null;
		boolean result = false;
		
		try{
			
			conn = this.openDatabase();
			pstmt = conn.prepareStatement(insertSQL);
				// ? 매개변수에 대입할 값 지정
				pstmt.setString(1, m.getUserid() );
				pstmt.setString(2, m.getPasswd() );
				pstmt.setString(3, m.getName() );
				pstmt.setString(4, m.getEmail() );
			pstmt.executeUpdate();
			result = true;
			
			
		} catch ( Exception ex ) {
			ex.printStackTrace(); 
		}finally {
			closeDatabase(conn, pstmt, null);
		}	
		return result;
	}	// insertMember

	
	// JDBC Connection 객체를 생성하는 메서드
	private Connection openDatabase(  ){
		try {
			Class.forName(DRV);
			return DriverManager.getConnection(URL);
		} catch (Exception e) {
					e.printStackTrace();
		}
		return null;
	}
	
	
	
	// JDBC 객체를 닫는 메서드
	private void closeDatabase( Connection c, PreparedStatement p, ResultSet r){
		 
				if ( r != null) try { r.close(); r =  null; } catch ( Exception e) {} 
				if ( p != null) try { p.close(); p =  null; } catch ( Exception e) {} 
				if ( c != null) try { c.close(); c =  null; } catch ( Exception e) {} 
			
				
			
	}
	
	
	
} // J03_MemberDAO
